package com.lill.sale.service.impl;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.lill.common.component.util.IdUtil;
import com.lill.product.service.ISaleRoyaltyService;
import com.lill.sale.dao.IRoyaltyOfSaleDao;
import com.lill.sale.service.IRoyaltyOfSaleService;

/**
 * 销售提成值Service实现类
 *
 * @author lill
 * @date 2021-09-06 20:23:17
 */
@Service("com.lill.sale.service.impl.RoyaltyOfSaleServiceImpl")
public class RoyaltyOfSaleServiceImpl implements IRoyaltyOfSaleService {
	
    @Autowired
    private IRoyaltyOfSaleDao royaltyOfSaleDao;
    @Autowired
    private ISaleRoyaltyService saleRoyaltyService;

    public Map<String, Object> queryObject(String id,String productCarId) {
    	Map<String, Object> royaltyMap=royaltyOfSaleDao.queryObject(id);
    	if(null==royaltyMap){
    		royaltyMap=saleRoyaltyService.queryObject(productCarId);
    		royaltyMap.remove("product_id");
    		royaltyMap.remove("productId");
    	}
    	royaltyMap.put("saleCarId", id);
        return royaltyMap;
    }

    public int save(Map<String, Object> royaltyMap) {
    	int num=royaltyOfSaleDao.queryTotal(royaltyMap);
    	if(royaltyMap.containsKey("saleCarId")){
    		royaltyMap.put("sale_car_id", royaltyMap.get("saleCarId"));
    		royaltyMap.remove("saleCarId");
    	}
    	if(num>0){
    		return royaltyOfSaleDao.update(royaltyMap);
    	}else{
    		royaltyMap.put("id", IdUtil.createIdbyUUID());
    		return royaltyOfSaleDao.save(royaltyMap);
    	}
    }

}
